<template>
  <div>
    <Head>分类</Head>
    <div class="list_wrapper">

      <div v-for="(item, index) in sortList" :key="index">
        <div class="sort_title">{{item.title}}</div>
        <div class="sort_list clearfix">
          <a class="sort_item" @click="sortJump(item.id, children.id)" v-for="(children, index) in item.children" :key="index"><span>{{children.title}}</span></a>
        </div>
      </div>

    </div>
  </div>
</template>

<script>
import http from '@/utils/http'
import api from '@/api'
export default{
  data () {
    return {
      sortList: []
    }
  },
  created () {
    this.getSortList()
  },
  methods: {
    // 分类列表数据获取
    getSortList () {
      http.get(api.type_tree).then(res => {
        if (res.code == 200) {
          this.sortList = res.data
          this.restructureSortList(res.data)
        }
      })
    },
    // 分类列表数据重构
    restructureSortList (data) {
      data.map(res => {
        res.children.unshift({
          id: 0,
          label: '全部',
          pid: '',
          title: '全部',
          value: 0
        })
      })
    },
    // 分类跳转
    sortJump (itemId, childrenId) {
      this.$router.push(`/cityinfo/infolist/${itemId}/${childrenId}`)
    }
  }
}
</script>

<style lang="scss" scoped>
.list_wrapper{
  margin: 0 13px;
  .sort_title{
    font-size: 15px;
    color: #333333;
    font-weight: bold;
    padding: 23px 0 19px;
  }
  .sort_list{
    .sort_item{
      width: 109px;
      height: 31px;
      display: block;
      float: left;
      margin-right: 9px;
      margin-bottom: 9px;
      color: #666666;
      font-size: 15px;
      text-align: center;
      line-height: 31px;
      background: #f4f4f4;
      border-radius: 5px;
      &:nth-of-type(3n){
        margin-right: 0;
      }
      span{
        display: block;
        margin: 0 10px;
        overflow: hidden;
        text-overflow: clip;
        white-space: nowrap;
      }
    }
  }
}
</style>
